#pragma once
#include "afxcolorbutton.h"
#include "ColorRGBA.h"
#include "afxwin.h"

// ColorSettingsDialog dialog

class CColorSettingsDialog : public CDialogEx
{
	DECLARE_DYNAMIC( CColorSettingsDialog )

public:
	CColorSettingsDialog( CWnd* pParent = NULL );   // standard constructor
	virtual ~CColorSettingsDialog( );

// Dialog Data
	enum { IDD = IDD_COLOR_SETTINGS_DLG };

    virtual BOOL OnInitDialog( );

    void setColors( const ColorRGBA& objectC,
                    const ColorRGBA& backgroundC,
                    const ColorRGBA& vertexNormalC,
                    const ColorRGBA& faceNormalC,
                    const ColorRGBA& boundingBoxC );

    void getColors( ColorRGBA& objectC,
                    ColorRGBA& backgroundC,
                    ColorRGBA& vertexNormalC,
                    ColorRGBA& faceNormalC,
                    ColorRGBA& boundingBoxC ) const;

    void restoreDefaults( );

    void setOverrideWireframeColor( int overrideWFColor );
    int  getOverrideWireframeColor( ) const;


protected:
	virtual void DoDataExchange( CDataExchange* pDX );    // DDX/DDV support

	DECLARE_MESSAGE_MAP( )

private:
    CMFCColorButton objectColorControl;
    CMFCColorButton backgroundColorControl;
    CMFCColorButton vertexNormalColorControl;
    CMFCColorButton faceNormalColorControl;
    CMFCColorButton boundingBoxColorControl;

    COLORREF objectColor,
             backgroundColor,
             vertexNormalColor,
             faceNormalColor,
             boundingBoxColor;

    CButton overrideWireframeColorControl;
    int     overrideWireframeColor;
        

public:
    afx_msg void OnBnClickedOk();
    afx_msg void OnBnClickedRestoreDefaults();
    afx_msg void OnBnClickedOverrideWireframeColor();
};


inline void CColorSettingsDialog::setColors( const ColorRGBA& objectC,
                                             const ColorRGBA& backgroundC,
                                             const ColorRGBA& vertexNormalC,
                                             const ColorRGBA& faceNormalC,
                                             const ColorRGBA& boundingBoxC )
{
    objectColor       = RGB( objectC.getR( )      *255, objectC.getG( )      *255, objectC.getB( )      *255 );
    backgroundColor   = RGB( backgroundC.getR( )  *255, backgroundC.getG( )  *255, backgroundC.getB( )  *255 );
    vertexNormalColor = RGB( vertexNormalC.getR( )*255, vertexNormalC.getG( )*255, vertexNormalC.getB( )*255 );
    faceNormalColor   = RGB( faceNormalC.getR( )  *255, faceNormalC.getG( )  *255, faceNormalC.getB( )  *255 );
    boundingBoxColor  = RGB( boundingBoxC.getR( ) *255, boundingBoxC.getG( ) *255, boundingBoxC.getB( ) *255 );
}


inline void CColorSettingsDialog::getColors( ColorRGBA& objectC,
                                             ColorRGBA& backgroundC,
                                             ColorRGBA& vertexNormalC,
                                             ColorRGBA& faceNormalC,
                                             ColorRGBA& boundingBoxC ) const
{
    objectC.setR( GetRValue( objectColor ) / 255.0f );
    objectC.setG( GetGValue( objectColor ) / 255.0f );
    objectC.setB( GetBValue( objectColor ) / 255.0f );

    backgroundC.setR( GetRValue( backgroundColor ) / 255.0f );
    backgroundC.setG( GetGValue( backgroundColor ) / 255.0f );
    backgroundC.setB( GetBValue( backgroundColor ) / 255.0f );

    vertexNormalC.setR( GetRValue( vertexNormalColor ) / 255.0f );
    vertexNormalC.setG( GetGValue( vertexNormalColor ) / 255.0f );
    vertexNormalC.setB( GetBValue( vertexNormalColor ) / 255.0f );

    faceNormalC.setR( GetRValue( faceNormalColor ) / 255.0f );
    faceNormalC.setG( GetGValue( faceNormalColor ) / 255.0f );
    faceNormalC.setB( GetBValue( faceNormalColor ) / 255.0f );

    boundingBoxC.setR( GetRValue( boundingBoxColor ) / 255.0f );
    boundingBoxC.setG( GetGValue( boundingBoxColor ) / 255.0f );
    boundingBoxC.setB( GetBValue( boundingBoxColor ) / 255.0f );
}


inline void CColorSettingsDialog::restoreDefaults( )
{
    objectColor       = RGB( 250, 170,  30 );
    backgroundColor   = RGB(   0,   0,   0 );
    vertexNormalColor = RGB( 218, 118, 218 );
    faceNormalColor   = RGB( 218, 118, 218 );
    boundingBoxColor  = RGB(  90, 240, 120 );
    overrideWireframeColor = 0;
}


inline void CColorSettingsDialog::setOverrideWireframeColor( int overrideWFColor )
{
    overrideWireframeColor = overrideWFColor;
}


inline int  CColorSettingsDialog::getOverrideWireframeColor( ) const
{
    return overrideWireframeColor;
}